{
  "name": "Case 80 - Customer Success - Power User Advocate Finder",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 9 * * 1"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -1088,
        -208
      ],
      "id": "5eac2119-ffd9-4f3e-9e77-e1ea61941b62",
      "name": "Weekly Schedule - Monday 9 AM"
    },
    {
      "parameters": {
        "actorId": {
          "__rl": true,
          "value": "buIWk2uOUzTmcLsuB",
          "mode": "list",
          "cachedResultName": "Linkedin Post Search Scraper (No Cookies) (harvestapi/linkedin-post-search)",
          "cachedResultUrl": "https://console.apify.com/actors/buIWk2uOUzTmcLsuB/input"
        },
        "customBody": "{\n  \"searchQueries\": [\n    \"Emergent\",\n    \"@Emergent\",\n    \"#Emergent\"\n  ],\n  \"maxPosts\": 50,\n  \"scrapeComments\": false,\n  \"scrapeReactions\": false\n}"
      },
      "type": "@apify/n8n-nodes-apify.apify",
      "typeVersion": 1,
      "position": [
        -912,
        -208
      ],
      "id": "987edebc-2895-4f52-9e8b-357184f179db",
      "name": "Scrape LinkedIn Brand Mentions",
      "credentials": {
        "apifyApi": {
          "id": "w5S6YBbbyUddEfQA",
          "name": "Apify account"
        }
      }
    },
    {
      "parameters": {
        "resource": "Datasets",
        "datasetId": "={{ $json.defaultDatasetId }}"
      },
      "type": "@apify/n8n-nodes-apify.apify",
      "typeVersion": 1,
      "position": [
        -736,
        -208
      ],
      "id": "9b1200a8-0cb3-48ea-afb9-9c691887c706",
      "name": "Get Dataset Items",
      "credentials": {
        "apifyApi": {
          "id": "w5S6YBbbyUddEfQA",
          "name": "Apify account"
        }
      }
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "GPT-4o-mini"
        },
        "responses": {
          "values": [
            {
              "role": "system",
              "content": "=You are a Brand Advocacy Validation Expert.\n\nAnalyze LinkedIn posts to determine if they are genuine brand advocacy (customers/users praising the company).\n\nReturn ONLY valid JSON in this exact format:\n{\n  \"is_brand_advocacy\": \"yes|no\",\n  \"confidence\": 0.95,\n  \"reason\": \"brief explanation\"\n}\n\nCriteria for \"yes\" (genuine brand advocacy):\n✅ User/customer sharing positive experience with the company\n✅ Unprompted praise or recommendation of the company\n✅ Success story using the company's platform/service\n✅ Testimonial or review content\n✅ Expressing gratitude or appreciation to the company\n✅ Sharing achievement enabled by the company\n✅ Defending the company in discussions\n✅ Recommending the company to others\n\nCriteria for \"no\" (NOT brand advocacy):\n❌ Company's own official posts (self-promotion)\n❌ Job postings mentioning the company\n❌ News articles or press releases\n❌ Complaints or negative feedback\n❌ Competitor comparisons (unless clearly favoring this brand)\n❌ Employee posts about working at the company\n❌ Sales/marketing posts from company staff\n❌ Neutral mentions without advocacy intent\n\nRules:\n1. confidence: 0-1 scale (0.9+ for very clear advocacy)\n2. reason: 1 sentence explaining the decision\n3. Be strict - require genuine customer advocacy, not just mentions\n4. Return ONLY the JSON object, no explanations"
            },
            {
              "content": "=Analyze this LinkedIn post to determine if it's genuine brand advocacy:\n\nAuthor: {{ $json.author.name }}\nAuthor Info: {{ $json.author.info }}\nPost Date: {{ $json.postedAt.date }}\nPost Content: {{ $json.content }}\n\nReturn only JSON."
            }
          ]
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.1,
      "position": [
        -592,
        -208
      ],
      "id": "6fdd1703-b620-4193-b5be-39cc3426d37b",
      "name": "AI Validation Filter",
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// UNIVERSAL AI RESPONSE PARSER - Same code for ALL cases\nconst items = [];\nconst input = $input.all();\n\nfunction extractJSON(text) {\n  const jsonMatch = text.match(/\\{[\\s\\S]*\\}/);\n  if (!jsonMatch) return null;\n  return jsonMatch[0];\n}\n\ninput.forEach((item, index) => {\n  try {\n    let aiText = item.json.output[0].content[0].text || '';\n    \n    // Clean markdown code blocks\n    aiText = aiText\n      .replace(/```json/gi, '')\n      .replace(/```/g, '')\n      .trim();\n    \n    // Extract JSON object\n    const jsonStr = extractJSON(aiText);\n    \n    if (!jsonStr) {\n      throw new Error('No JSON found in AI response');\n    }\n    \n    // Parse and return clean JSON\n    const parsed = JSON.parse(jsonStr);\n    items.push({ json: parsed });\n    \n  } catch (error) {\n    console.error(`Parse error for item ${index}:`, error.message);\n    // Return empty object on error - no case-specific fields\n    items.push({ json: {} });\n  }\n});\n\nreturn items;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -304,
        -208
      ],
      "id": "04f25a82-8d0f-4a69-8a74-c4d9135f2992",
      "name": "Parse AI Validation"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "is_brand_advocacy",
              "name": "is_brand_advocacy",
              "value": "={{ $json.is_brand_advocacy }}",
              "type": "string"
            },
            {
              "id": "confidence",
              "name": "confidence",
              "value": "={{ $json.confidence }}",
              "type": "number"
            },
            {
              "id": "reason",
              "name": "reason",
              "value": "={{ $json.reason }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -128,
        -208
      ],
      "id": "dd7d06d9-e2e9-46ff-8be4-fc8d1d72a797",
      "name": "Edit Fields - Validation"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "condition-001",
              "leftValue": "={{ $json.is_brand_advocacy }}",
              "rightValue": "yes",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2,
      "position": [
        32,
        -208
      ],
      "id": "42119982-3060-4898-9da9-a5b6f0ee36e2",
      "name": "Filter Only Brand Advocates"
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "GPT-4o-mini"
        },
        "responses": {
          "values": [
            {
              "role": "system",
              "content": "=You are a Brand Advocacy Intelligence Analyst.\n\nExtract structured brand advocate information from LinkedIn posts.\n\nReturn ONLY valid JSON in this exact format:\n{\n  \"advocacy_level\": \"Evangelist|Fan|Satisfied|Neutral\",\n  \"use_case_shared\": \"What problem/use case they describe (max 150 chars)\",\n  \"influence_level\": \"High|Medium|Low\",\n  \"testimonial_quality\": \"Excellent|Good|Fair|Poor\",\n  \"case_study_potential\": \"Yes|No\",\n  \"ambassador_fit\": \"Yes|No\",\n  \"product_mentioned\": \"Specific product/feature if mentioned, otherwise 'General Platform'\",\n  \"sentiment\": \"Positive|Neutral|Mixed\"\n}\n\nExtraction Rules:\n1. advocacy_level:\n   - Evangelist = Unprompted enthusiastic praise, recommending to others\n   - Fan = Positive mention, sharing success\n   - Satisfied = Neutral positive mention\n   - Neutral = Factual mention without emotion\n\n2. use_case_shared: Summarize what they accomplished/solved\n\n3. influence_level (based on engagement metrics in post):\n   - High = 500+ engagement (likes + comments + shares)\n   - Medium = 50-499 engagement\n   - Low = <50 engagement\n\n4. testimonial_quality:\n   - Excellent = Specific results, quotable, compelling\n   - Good = Clear benefit, usable\n   - Fair = Vague but positive\n   - Poor = Too generic\n\n5. case_study_potential:\n   - Yes = Detailed story with specific outcomes\n   - No = Too brief or vague\n\n6. ambassador_fit:\n   - Yes = High engagement, enthusiastic, would likely participate\n   - No = Low engagement or one-off mention\n\n7. product_mentioned: Extract specific product/feature name\n\n8. sentiment: Overall tone\n\nReturn ONLY the JSON object, no explanations."
            },
            {
              "content": "=Extract brand advocate intelligence from this LinkedIn post:\n\nAuthor: {{ $('Get Dataset Items').item.json.author.name }}\nAuthor Info: {{ $('Get Dataset Items').item.json.author.info }}\nPost Date: {{ $('Get Dataset Items').item.json.postedAt.date }}\nPost Content: {{ $('Get Dataset Items').item.json.content }}\nEngagement: {{ $('Get Dataset Items').item.json.engagement.likes }} likes, {{ $('Get Dataset Items').item.json.engagement.comments }} comments, {{ $('Get Dataset Items').item.json.engagement.shares }} shares\n\nReturn only JSON."
            }
          ]
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.1,
      "position": [
        208,
        -208
      ],
      "id": "5ec953cd-a883-4797-98c7-4c32b43ef6a2",
      "name": "AI Extract Advocate Intelligence",
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// UNIVERSAL AI RESPONSE PARSER - Same code for ALL cases\nconst items = [];\nconst input = $input.all();\n\nfunction extractJSON(text) {\n  const jsonMatch = text.match(/\\{[\\s\\S]*\\}/);\n  if (!jsonMatch) return null;\n  return jsonMatch[0];\n}\n\ninput.forEach((item, index) => {\n  try {\n    let aiText = item.json.output[0].content[0].text || '';\n    \n    // Clean markdown code blocks\n    aiText = aiText\n      .replace(/```json/gi, '')\n      .replace(/```/g, '')\n      .trim();\n    \n    // Extract JSON object\n    const jsonStr = extractJSON(aiText);\n    \n    if (!jsonStr) {\n      throw new Error('No JSON found in AI response');\n    }\n    \n    // Parse and return clean JSON\n    const parsed = JSON.parse(jsonStr);\n    items.push({ json: parsed });\n    \n  } catch (error) {\n    console.error(`Parse error for item ${index}:`, error.message);\n    // Return empty object on error - no case-specific fields\n    items.push({ json: {} });\n  }\n});\n\nreturn items;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        -208
      ],
      "id": "207d5d10-5266-4f64-a460-c31004c151be",
      "name": "Parse AI Response"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "timestamp",
              "name": "analysis_timestamp",
              "value": "={{ new Date().toISOString() }}",
              "type": "string"
            },
            {
              "id": "advocate_name",
              "name": "advocate_name",
              "value": "={{ $('Get Dataset Items').item.json.author?.name || 'unknown' }}",
              "type": "string"
            },
            {
              "id": "advocate_profile",
              "name": "advocate_profile",
              "value": "={{ $('Get Dataset Items').item.json.author?.linkedinUrl || '' }}",
              "type": "string"
            },
            {
              "id": "advocate_info",
              "name": "advocate_info",
              "value": "={{ $('Get Dataset Items').item.json.author?.info || '' }}",
              "type": "string"
            },
            {
              "id": "advocacy_level",
              "name": "advocacy_level",
              "value": "={{ $json.advocacy_level }}",
              "type": "string"
            },
            {
              "id": "use_case",
              "name": "use_case_shared",
              "value": "={{ $json.use_case_shared }}",
              "type": "string"
            },
            {
              "id": "influence",
              "name": "influence_level",
              "value": "={{ $json.influence_level }}",
              "type": "string"
            },
            {
              "id": "testimonial",
              "name": "testimonial_quality",
              "value": "={{ $json.testimonial_quality }}",
              "type": "string"
            },
            {
              "id": "case_study",
              "name": "case_study_potential",
              "value": "={{ $json.case_study_potential }}",
              "type": "string"
            },
            {
              "id": "ambassador",
              "name": "ambassador_fit",
              "value": "={{ $json.ambassador_fit }}",
              "type": "string"
            },
            {
              "id": "product",
              "name": "product_mentioned",
              "value": "={{ $json.product_mentioned }}",
              "type": "string"
            },
            {
              "id": "sentiment",
              "name": "sentiment",
              "value": "={{ $json.sentiment }}",
              "type": "string"
            },
            {
              "id": "post_content",
              "name": "post_content",
              "value": "={{ $('Get Dataset Items').item.json.content || '' }}",
              "type": "string"
            },
            {
              "id": "post_date",
              "name": "post_date",
              "value": "={{ $('Get Dataset Items').item.json.postedAt?.date || '' }}",
              "type": "string"
            },
            {
              "id": "post_url",
              "name": "post_url",
              "value": "={{ $('Get Dataset Items').item.json.linkedinUrl || '' }}",
              "type": "string"
            },
            {
              "id": "likes",
              "name": "likes_count",
              "value": "={{ $('Get Dataset Items').item.json.engagement?.likes || 0 }}",
              "type": "number"
            },
            {
              "id": "comments",
              "name": "comments_count",
              "value": "={{ $('Get Dataset Items').item.json.engagement?.comments || 0 }}",
              "type": "number"
            },
            {
              "id": "shares",
              "name": "shares_count",
              "value": "={{ $('Get Dataset Items').item.json.engagement?.shares || 0 }}",
              "type": "number"
            },
            {
              "id": "total_engagement",
              "name": "engagement_total",
              "value": "={{ ($('Get Dataset Items').item.json.engagement?.likes || 0) + ($('Get Dataset Items').item.json.engagement?.comments || 0) + ($('Get Dataset Items').item.json.engagement?.shares || 0) }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        656,
        -208
      ],
      "id": "a58720e4-af08-49cf-948a-717b6e41f1c5",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1AaHPxDEKshT2h_NDEGw1nnj2HnKC_uZRgS2UWd9tDDQ",
          "mode": "list",
          "cachedResultName": "Case 80 - Customer success brand advocate log",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1AaHPxDEKshT2h_NDEGw1nnj2HnKC_uZRgS2UWd9tDDQ/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1AaHPxDEKshT2h_NDEGw1nnj2HnKC_uZRgS2UWd9tDDQ/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Analysis_Date": "={{ $json.analysis_timestamp }}",
            "Advocate_Name": "={{ $json.advocate_name }}",
            "Advocate_Info": "={{ $json.advocate_info }}",
            "Advocacy_Level": "={{ $json.advocacy_level }}",
            "Use_Case_Shared": "={{ $json.use_case_shared }}",
            "Influence_Level": "={{ $json.influence_level }}",
            "Testimonial_Quality": "={{ $json.testimonial_quality }}",
            "Case_Study_Potential": "={{ $json.case_study_potential }}",
            "Ambassador_Fit": "={{ $json.ambassador_fit }}",
            "Product_Mentioned": "={{ $json.product_mentioned }}",
            "Sentiment": "={{ $json.sentiment }}",
            "Post_Date": "={{ $json.post_date }}",
            "Likes": "={{ $json.likes_count }}",
            "Comments": "={{ $json.comments_count }}",
            "Shares": "={{ $json.shares_count }}",
            "Total_Engagement": "={{ $json.engagement_total }}",
            "Advocate_Profile": "={{ $json.advocate_profile }}",
            "Post_URL": "={{ $json.post_url }}",
            "Post_Content": "={{ $json.post_content }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Analysis_Date",
              "displayName": "Analysis_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Advocate_Name",
              "displayName": "Advocate_Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Advocate_Info",
              "displayName": "Advocate_Info",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Advocacy_Level",
              "displayName": "Advocacy_Level",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Use_Case_Shared",
              "displayName": "Use_Case_Shared",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Influence_Level",
              "displayName": "Influence_Level",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Testimonial_Quality",
              "displayName": "Testimonial_Quality",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Case_Study_Potential",
              "displayName": "Case_Study_Potential",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Ambassador_Fit",
              "displayName": "Ambassador_Fit",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Product_Mentioned",
              "displayName": "Product_Mentioned",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Sentiment",
              "displayName": "Sentiment",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Post_Date",
              "displayName": "Post_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Likes",
              "displayName": "Likes",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Comments",
              "displayName": "Comments",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Shares",
              "displayName": "Shares",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Total_Engagement",
              "displayName": "Total_Engagement",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Advocate_Profile",
              "displayName": "Advocate_Profile",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Post_URL",
              "displayName": "Post_URL",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Post_Content",
              "displayName": "Post_Content",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        832,
        -208
      ],
      "id": "61ca9445-8831-4748-8bb8-2466ee2bdf7b",
      "name": "Log to Google Sheet",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Aggregate all items from Google Sheets into email-ready summary\nconst allItems = $input.all();\n\n// Count by advocacy level\nconst advocacyCounts = {};\nallItems.forEach(item => {\n  const level = item.json.Advocacy_Level || 'Unknown';\n  advocacyCounts[level] = (advocacyCounts[level] || 0) + 1;\n});\n\n// Count by influence level\nconst influenceCounts = {};\nallItems.forEach(item => {\n  const influence = item.json.Influence_Level || 'Unknown';\n  influenceCounts[influence] = (influenceCounts[influence] || 0) + 1;\n});\n\n// Count excellent testimonials\nconst excellentTestimonials = allItems.filter(item => \n  item.json.Testimonial_Quality === 'Excellent'\n);\n\n// Count case study potential\nconst caseStudyCandidates = allItems.filter(item => \n  item.json.Case_Study_Potential === 'Yes'\n);\n\n// Count ambassador fit\nconst ambassadorCandidates = allItems.filter(item => \n  item.json.Ambassador_Fit === 'Yes'\n);\n\n// Evangelists (highest priority)\nconst evangelists = allItems.filter(item => \n  item.json.Advocacy_Level === 'Evangelist'\n);\n\n// Products mentioned\nconst productCounts = {};\nallItems.forEach(item => {\n  const product = item.json.Product_Mentioned || 'General Platform';\n  productCounts[product] = (productCounts[product] || 0) + 1;\n});\n\nconst topProducts = Object.entries(productCounts)\n  .sort((a, b) => b[1] - a[1])\n  .slice(0, 5);\n\n// Build HTML table rows\nconst tableRows = allItems.map(item => {\n  const data = item.json;\n  const levelColor = data.Advocacy_Level === 'Evangelist' ? '#28a745' : \n                     data.Advocacy_Level === 'Fan' ? '#17a2b8' : '#6c757d';\n  \n  return `\n    <tr>\n      <td>${data.Advocate_Name || 'N/A'}</td>\n      <td><span style=\"color: ${levelColor}; font-weight: bold;\">${data.Advocacy_Level || 'N/A'}</span></td>\n      <td>${data.Influence_Level || 'N/A'}</td>\n      <td>${data.Testimonial_Quality || 'N/A'}</td>\n      <td>${data.Case_Study_Potential || 'N/A'}</td>\n      <td>${data.Ambassador_Fit || 'N/A'}</td>\n      <td><a href=\"${data.Post_URL || '#'}\">View</a></td>\n    </tr>\n  `;\n}).join('');\n\n// Return single aggregated item\nreturn {\n  json: {\n    week_start: new Date(Date.now() - 7*24*60*60*1000).toISOString().split('T')[0],\n    week_end: new Date().toISOString().split('T')[0],\n    total_advocates: allItems.length,\n    advocacy_breakdown: Object.entries(advocacyCounts),\n    influence_breakdown: Object.entries(influenceCounts),\n    excellent_testimonials_count: excellentTestimonials.length,\n    case_study_candidates_count: caseStudyCandidates.length,\n    ambassador_candidates_count: ambassadorCandidates.length,\n    evangelists_count: evangelists.length,\n    top_products: topProducts,\n    table_rows: tableRows,\n    all_advocates: allItems.map(item => item.json)\n  }\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1008,
        -208
      ],
      "id": "7181fc45-df36-4149-930a-5b515effb69a",
      "name": "Aggregate Weekly Summary"
    },
    {
      "parameters": {
        "sendTo": "customer-success@yourcompany.com",
        "subject": "=📊 Weekly Brand Advocate Report: {{ $json.week_start }} to {{ $json.week_end }}",
        "message": "=WEEKLY BRAND ADVOCATE INTELLIGENCE REPORT\n================================================\nReport Period: {{ $json.week_start }} to {{ $json.week_end }}\n\nOVERVIEW:\nTotal Brand Advocates Identified: {{ $json.total_advocates }}\nEvangelists (Highest Priority): {{ $json.evangelists_count }}\nExcellent Testimonials: {{ $json.excellent_testimonials_count }}\nCase Study Candidates: {{ $json.case_study_candidates_count }}\nAmbassador Program Candidates: {{ $json.ambassador_candidates_count }}\n\nADVOCACY LEVEL BREAKDOWN:\n{{ $json.advocacy_breakdown.map(([level, count]) => level + ': ' + count).join('\\n') }}\n\nINFLUENCE LEVEL DISTRIBUTION:\n{{ $json.influence_breakdown.map(([influence, count]) => influence + ': ' + count).join('\\n') }}\n\nTOP PRODUCTS/FEATURES MENTIONED:\n{{ $json.top_products.map(([product, count], i) => (i+1) + '. ' + product + ' (' + count + ' mentions)').join('\\n') }}\n\n🎯 PRIORITY ACTIONS:\n✅ {{ $json.evangelists_count }} evangelists to reach out for testimonials\n✅ {{ $json.case_study_candidates_count }} case study opportunities\n✅ {{ $json.ambassador_candidates_count }} ambassador program prospects\n\nFull advocate details in Google Sheets.\n\nGenerated: {{ new Date().toLocaleDateString() }}",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1184,
        -208
      ],
      "id": "a7e74e04-62bd-445d-8ff9-d29015064a29",
      "name": "Send Weekly Summary Email",
      "webhookId": "c9f6837f-7cca-45fa-a56b-95a7a9a99823",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Weekly Schedule - Monday 9 AM": {
      "main": [
        [
          {
            "node": "Scrape LinkedIn Brand Mentions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scrape LinkedIn Brand Mentions": {
      "main": [
        [
          {
            "node": "Get Dataset Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Dataset Items": {
      "main": [
        [
          {
            "node": "AI Validation Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Validation Filter": {
      "main": [
        [
          {
            "node": "Parse AI Validation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI Validation": {
      "main": [
        [
          {
            "node": "Edit Fields - Validation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields - Validation": {
      "main": [
        [
          {
            "node": "Filter Only Brand Advocates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Only Brand Advocates": {
      "main": [
        [
          {
            "node": "AI Extract Advocate Intelligence",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Extract Advocate Intelligence": {
      "main": [
        [
          {
            "node": "Parse AI Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI Response": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Log to Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to Google Sheet": {
      "main": [
        [
          {
            "node": "Aggregate Weekly Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Weekly Summary": {
      "main": [
        [
          {
            "node": "Send Weekly Summary Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a933d844-a883-40ee-95dc-6fa186cbac0e",
  "meta": {
    "instanceId": "3a43da28588548e21903e71cf1dc3ddd65c24bf0c62e7e4b77542ffe87ad79c6"
  },
  "id": "x1e7oWkg24HmoqW0",
  "tags": []
}